/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.verify;

import picounit.Registry;
import picounit.Verify;
import picounit.features.Feature;
import picounit.features.aggregate_exception.Thrower;
import picounit.features.base.FeatureRegistry;
import picounit.features.mocking.Verifiable;
import picounit.features.terminal_reason.ReasonRegistry;
import picounit.features.verify.constraint.UnconditionalEvaluator;

public class VerifyFeature implements Feature {
	private final Thrower thrower;
	private final Registry registry;
	private final Verifiable verifiable;
	private final ReasonRegistry reasonRegistry;

	public VerifyFeature(Thrower thrower, Registry registry, Verifiable verifiable,
		ReasonRegistry reasonRegistry) {

		this.thrower = thrower;
		this.registry = registry;
		this.verifiable = verifiable;
		this.reasonRegistry = reasonRegistry;
	}

	public void addFeatures(FeatureRegistry featureRegistry) {
		Evaluator evaluator = new ConditionalEvaluator(
			new UnconditionalEvaluator(thrower, verifiable), reasonRegistry);

		Verify verify = new DefaultVerify(evaluator, thrower, new CombinedConstraints(evaluator));

		registry.register(Verify.class, verify);

		// Register this for the sake of custom Verify classes
		registry.register(Evaluator.class, evaluator);

		featureRegistry.addFeatures(verify);
	}
}
